home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / elk-2_0.lha / elk-2.0 / src / load.rld.c < prev    next >
C/C++ Source or Header  |  1992-10-27  |  2KB  |  69 lines

  1. #include <mach-o/rld.h>
  2.  
  3. Load_Object (names) Object names; {
  4.     long retval;
  5.     struct mach_header *hdr;
  6.     char **filenames, *libs;
  7.     NXStream *err_stream;
  8.     register i, n;
  9.     Object port, tail, fullnames;
  10.     extern char *strtok();
  11.     GC_Node3;
  12.     Alloca_Begin;
  13.  
  14.     port = tail = fullnames = Null;
  15.     GC_Link3 (port, tail, fullnames);
  16.     for (n = 0, tail = names; !Nullp (tail); n++, tail = Cdr (tail)) {
  17.     port = General_Open_File (Car (tail), P_INPUT, Var_Get (V_Load_Path));
  18.     fullnames = Cons (PORT(port)->name, fullnames);
  19.     (void)P_Close_Input_Port (port);
  20.     }
  21.     GC_Unlink;
  22.  
  23.     libs = "";
  24.     tail = Var_Get (V_Load_Libraries);
  25.     if (TYPE(tail) == T_String)
  26.     Make_C_String (tail, libs);
  27.  
  28.     Alloca (filenames, char**, (n+1 + strlen(libs)/2) * sizeof(char *));
  29.     for (i = 0; i < n; i++, fullnames = Cdr (fullnames)) {
  30.     Object s = Car (fullnames);
  31.     Make_C_String (s, filenames[i]);
  32.     }
  33.  
  34.     /* Append the load-libraries to the end of the list of filenames
  35.      * to be passed to rld_load:
  36.      */
  37.     for ( ; (filenames[i] = strtok (libs, " \t")) != 0; i++, libs = 0)
  38.     ;
  39.     if (Verbose) {
  40.     printf ("rld_load: ");
  41.     for (i = 0; filenames[i]; i++) printf ("%s ", filenames[i]);
  42.     printf("\n");
  43.     }
  44.  
  45.     Disable_Interrupts;
  46.     /* Construct a stream for error logging:
  47.      */
  48.     if ((err_stream = NXOpenFile (fileno (stderr), NX_WRITEONLY)) == 0)
  49.     Primitive_Error ("NXOpenFile failed");
  50.  
  51.     retval = rld_load (err_stream, /* report error messages here */
  52.     &hdr,                      /* return header address here */
  53.     filenames,                 /* load these */
  54.     "/dev/null");              /* doesn't work if NULL?! */
  55.     NXClose (err_stream);
  56.     if (retval != 1)
  57.     Primitive_Error ("rld_load() failed");
  58.  
  59.     /* Grab the symbol table from the just-loaded file:
  60.      */
  61.     if (The_Symbols)
  62.     Free_Symbols (The_Symbols);
  63.     The_Symbols = Snarf_Symbols (hdr);
  64.     if (!Call_Initializers (The_Symbols, 0))
  65.     Primitive_Error ("no initializers in object file(s)");
  66.     Enable_Interrupts;
  67.     Alloca_End;
  68. }
  69.